package o2o.web.actions.sys;

import com.jinyou.utils.common.AjaxResult;
import com.jinyou.utils.common.ObjectUtils;
import com.jinyou.utils.common.ValidateUtil;
import o2o.cache.system.SysSettingMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserOnlineImpl;
import o2o.config.dao.UserDaoSql;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.sys.SysSetting;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.VO.sys.SysConfigPathUserVO;
import o2o.dao.VO.sys.SysSettingUserVO;
import o2o.dao.VO.sys.SysSettingVO;
import o2o.service.sys.SysSettingService;
import o2o.system.SysSettings;
import o2o.system.data.SYS_CONFIG_PATH;
import o2o.system.data.SYS_SETTINGS;
import o2o.web.actions.order.user.UserOrderMan;
import o2o.web.actions.user.User;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

//系统设置

@Controller
public class SysSettingsAction {

    //获取所有系统设置
    @RequestMapping(method = RequestMethod.POST, value = "/admin/sys/settings/list")
    @ResponseBody
    public String sys_list(String token) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证是否有登录权限
        if (!User.getInstance().hasSuperAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您没有访问权限");
        }

        List<SysSetting> list = SysSettingMemory.getInstance().list();
        if (ValidateUtil.isAbsList(list)) {
            List<SysSettingVO> voList = new ArrayList<SysSettingVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                if (0 == list.get(i).getIsShow()) {
                    continue;
                }

                SysSettingVO sysSettingVO = new SysSettingVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), sysSettingVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                voList.add(sysSettingVO);
            }
            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }

        return AjaxResult.successResult(0, null);
    }

    //修改系统设置
    @RequestMapping(method = RequestMethod.POST, value = "/admin/sys/settings/modify")
    @ResponseBody
    public String sys_modify(String token, SysSettingVO info) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        //验证是否有登录权限
        if (!User.getInstance().hasSuperAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您没有访问权限");
        }

        if (null == info) {
            return AjaxResult.errorResult("请补全信息");
        }

        if (ValidateUtil.isNull(info.getName())) {
            return AjaxResult.errorResult("名称不能为空");
        }

        SysSetting sysSetting = SysSettingMemory.getInstance().getByCode(info.getName());
        if (null == sysSetting) {
            return AjaxResult.errorResult("未找到该项设置，请查证");
        }
        switch (info.getName()) {
            case "isOpenIntegral": {
                if (info.getVal() != null && "1".equals(info.getVal())) {
                    try {
                        SysSettingService.getInstance().createIntegerShop();
                    } catch (Exception e) {
                        e.printStackTrace();
                        return AjaxResult.errorResult("修改失败,请稍后重试");
                    }
                }
            }
            break;
        }
        StringBuilder sb = new StringBuilder();
//        sb.append("update ").append(PojoTables.SYS_SETTING).append(" set val='").append(info.getVal()).append("',descs='").append(info.getDescs())
//                .append("',note='").append(info.getNote()).append("',updateUser='")
//                .append(user.getUsername()).append("' where delFlag = 0 and code = '").append(info.getName()).append("'");
        sb.append("update ").append(PojoTables.SYS_SETTING).append(" set val='").append(info.getVal()).append("'")
                .append(",updateUser='").append(user.getUsername()).append("'");
        if (StringUtils.isNotEmpty(info.getNote())) {
            sb.append(", note ='").append(info.getNote()).append("'");
        }
        if (StringUtils.isNotEmpty(info.getDescs())) {
            sb.append(", descs = '").append(info.getDescs()).append("'");
        }
        sb.append(" where delFlag = 0 and code = '").append(info.getName()).append("'");
        System.out.println(sb.toString());
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
            return AjaxResult.errorResult("修改失败，请稍后再试");
        }
        //修改缓存
//        SysSettingMemory.getInstance().modifyByName(info.getName());
        SysSettings.init();//重新初始化系统值

        return AjaxResult.successResult();
    }

    //删除系统设置
    @RequestMapping(method = RequestMethod.POST, value = "/admin/sys/settings/delete")
    @ResponseBody
    public String sys_delete(String token, String name) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证是否有登录权限
        if (!User.getInstance().hasSuperAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您没有访问权限");
        }


        if (ValidateUtil.isNull(name)) {
            return AjaxResult.errorResult("名称不能为空");
        }


        SysSetting sysSetting = SysSettingMemory.getInstance().getByCode(name);
        if (null == sysSetting) {
            return AjaxResult.errorResult("未找到该项设置，请查证");
        }

        StringBuilder sb = new StringBuilder();
        sb.append("update ").append(PojoTables.SYS_SETTING).append(" set delFlag = 1,updateUser = '").append(user.getUsername())
                .append("'  where delFlag = 0 and code = '").append(name).append("'");

        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
            return AjaxResult.errorResult("删除失败，请稍后再试");
        }

        //修改缓存
//        SysSettingMemory.getInstance().deleteByName(name);

        SysSettings.init();//重新初始化系统值

        return AjaxResult.successResult();
    }

    /**
     * --------------------------
     */
    // 用户获取系统配置
    @RequestMapping(method = RequestMethod.POST, value = "/sys/settings")
    @ResponseBody
    public String sys_user_list(String token) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        SysSettingUserVO settingUserVO = new SysSettingUserVO();

        if (null == SYS_SETTINGS.URGENT_DELIVERY_PRICE) {
            settingUserVO.setUrgentDeliveryPrice(0);
        } else {
            settingUserVO.setUrgentDeliveryPrice(SYS_SETTINGS.URGENT_DELIVERY_PRICE);
        }

        if (null == SYS_SETTINGS.DELIVERY_RANGE) {
            settingUserVO.setDeliveryRange(0);
        } else {
            settingUserVO.setDeliveryRange(SYS_SETTINGS.DELIVERY_RANGE);
        }

        if (null == SYS_SETTINGS.DOOR_REFRESH_TIME) {   // 门禁刷新的时间（小志）
            settingUserVO.setDoorRefreshTime(0);
        } else {
            settingUserVO.setDoorRefreshTime(SYS_SETTINGS.DOOR_REFRESH_TIME);
        }

        //配送费计算方式
        if (null == SYS_SETTINGS.SELECT_DISTRIBUTION_FEE) {
            settingUserVO.setShopDeliveryPriceType(1);
        } else {
            settingUserVO.setShopDeliveryPriceType(SYS_SETTINGS.SELECT_DISTRIBUTION_FEE);
        }

        //当前汇率
        if (ValidateUtil.isNotAbsDouble(SYS_SETTINGS.EXCHANGE_RATE)) {
            settingUserVO.setExchangeRate(0d);
        } else {
            settingUserVO.setExchangeRate(SYS_SETTINGS.EXCHANGE_RATE);
        }

        //当前货币单位
        if (ValidateUtil.isNull(SYS_SETTINGS.CURRENCY_UNIT)) {
            settingUserVO.setCurrencyUnit("￥");
        } else {
            settingUserVO.setCurrencyUnit(SYS_SETTINGS.CURRENCY_UNIT);
        }

        // 是否使用主币支付 1使用主币支付 0使用外币支付
        if (null != SYS_SETTINGS.USE_MAIN_CURRENCY_PAY) {
            settingUserVO.setUseMainCurrencyPay(SYS_SETTINGS.USE_MAIN_CURRENCY_PAY);
        } else {
            settingUserVO.setUseMainCurrencyPay(1);
        }

        // 是否使用主币提现 1使用主币支付 0使用外币支付
        if (null != SYS_SETTINGS.USE_MAIN_CURRENCY_POP) {
            settingUserVO.setUseMainCurrencyPop(SYS_SETTINGS.USE_MAIN_CURRENCY_POP);
        } else {
            settingUserVO.setUseMainCurrencyPop(1);
        }

        // 支持货到付款？
        if (ValidateUtil.isNull(SYS_SETTINGS.IS_CASH_ON_DELIVERY)) {
            settingUserVO.setIsCashOnDelivery(0);
        } else {
            settingUserVO.setIsCashOnDelivery(SYS_SETTINGS.IS_CASH_ON_DELIVERY);
        }

        //商品折扣与满减：0满减和折扣能够同时使用，1只能使用折扣，2只能使用满减，3根据用户选择其一处理
        if (null == SYS_SETTINGS.AWARD_AND_SALE_MODEL) {
            settingUserVO.setAwardAndSaleModel(0);
        } else {
            settingUserVO.setAwardAndSaleModel(SYS_SETTINGS.AWARD_AND_SALE_MODEL);
        }

        // 店铺属于多个商圈
        settingUserVO.setShopBelongMultipleAgent(SYS_SETTINGS.SHOP_BELONG_MULTIPLE_AGENT);
        // 打包费分成
        settingUserVO.setShareShopPacketMoney(SYS_SETTINGS.SHARE_SHOP_PACKET_MONEY);
        // 是不是抽成单个商品
        settingUserVO.setIsPlateGoodsDrawMoney(SYS_SETTINGS.IS_PLATE_GOODS_DRAW_MONEY);
        // sellCountType 销量类型
        if (null == SYS_SETTINGS.SELL_COUNT_TYPE) {
            settingUserVO.setSellCountType(1); // 默认总销量
        } else {
            settingUserVO.setSellCountType(SYS_SETTINGS.SELL_COUNT_TYPE);
        }

        // 是否启用原材料
        if (null == SYS_SETTINGS.USE_ORIGINAL_MATERIAL) {
            settingUserVO.setUseOriginalMaterial(0); // 默认不启用材料
        } else {
            settingUserVO.setUseOriginalMaterial(SYS_SETTINGS.USE_ORIGINAL_MATERIAL);
        }
        // 积分抵用的百分比
        if (null == SYS_SETTINGS.INTEGRAL_PERCENT) {
            settingUserVO.setIntegralPercent(0); // 积分抵用百分比
        } else {
            settingUserVO.setIntegralPercent(SYS_SETTINGS.INTEGRAL_PERCENT);
        }
        // 跑腿上下班设置
        if (null == SYS_SETTINGS.PAOTUI_WORK_SETTING) {
            settingUserVO.setPaotuiWorkSetting(0); // 跑腿上下班设置
        } else {
            settingUserVO.setPaotuiWorkSetting(SYS_SETTINGS.PAOTUI_WORK_SETTING);
        }

        //  显示新旧界面
        if (null == SYS_SETTINGS.IS_NEW_VERSION_PAGE) {
            settingUserVO.setIsNewVersionPage(0); // 默认使用旧版
        } else {
            settingUserVO.setIsNewVersionPage(SYS_SETTINGS.IS_NEW_VERSION_PAGE);
        }
        // 是否开启积分模块
        if (null == SYS_SETTINGS.IS_OPEN_INTEGRAL) {
            settingUserVO.setIsOpenIntegral(0); // 不开启积分
        } else {
            settingUserVO.setIsOpenIntegral(SYS_SETTINGS.IS_OPEN_INTEGRAL);
        }

        //商品是否显示折扣标识  1显示 0不显示
        if (null == SYS_SETTINGS.IS_SHOW_ZHE_KOU_TIP) {
            settingUserVO.setIsShowZhekouTip(0);
        } else {
            settingUserVO.setIsShowZhekouTip(SYS_SETTINGS.IS_SHOW_ZHE_KOU_TIP);
        }

        //是否自动折扣 1现价比原价低就是折扣商品 0手动设置折扣
        if (null == SYS_SETTINGS.IS_AUTO_ZHE_KOU_GOOD) {
            settingUserVO.setIsAutoZhekouGood(1);
        } else {
            settingUserVO.setIsAutoZhekouGood(SYS_SETTINGS.IS_AUTO_ZHE_KOU_GOOD);
        }

        // 折扣不参见满减运费  0 参加满减运费 1 不参加
        if (null == SYS_SETTINGS.ZHEKOU_NOT_JOIN_FEE_YUNFEI) {
            settingUserVO.setZhekouNotJoinFeeYunfei(0);
        } else {
            settingUserVO.setZhekouNotJoinFeeYunfei(SYS_SETTINGS.ZHEKOU_NOT_JOIN_FEE_YUNFEI);
        }
        //配送员必须缴纳押金才能使用 0无需缴纳 1必须缴纳
        if (null == SYS_SETTINGS.POSTMAN_MUST_DEPOSIT) {
            settingUserVO.setPostmanMustDeposit(0);
        } else {
            settingUserVO.setPostmanMustDeposit(SYS_SETTINGS.POSTMAN_MUST_DEPOSIT);
        }
        //配送员必须认证才能使用 0无需认证 1必须认证
        if (null == SYS_SETTINGS.POSTMAN_MUST_VERIFY) {
            settingUserVO.setPostmanMustVerify(0);
        } else {
            settingUserVO.setPostmanMustVerify(SYS_SETTINGS.POSTMAN_MUST_VERIFY);
        }
        //配送员必须人脸实名认证才能使用 0无需认证 1必须认证
        if (null == SYS_SETTINGS.POSTMAN_MUST_VERIFY_FACE) {
            settingUserVO.setPostmanMustVerifyFace(0);
        } else {
            settingUserVO.setPostmanMustVerifyFace(SYS_SETTINGS.POSTMAN_MUST_VERIFY_FACE);
        }

        //跑腿使用的重量等是否可以按商圈设置  1按商圈 0全平台统一
        if (null == SYS_SETTINGS.PAOTUI_TIP_INFO_AGENT) {
            settingUserVO.setPaotuiTipInfoAgent(0);
        } else {
            settingUserVO.setPaotuiTipInfoAgent(SYS_SETTINGS.PAOTUI_TIP_INFO_AGENT);
        }
        //城代是否参与分成（0不参与，1参与）
        if (null == SYS_SETTINGS.IS_SYS_CITY_ADMIN_SHARE_MONEY) {
            settingUserVO.setIsSysCityAdminShareMoney(0);
        } else {
            settingUserVO.setIsSysCityAdminShareMoney(SYS_SETTINGS.IS_SYS_CITY_ADMIN_SHARE_MONEY);
        }
        //平台抽取城代分成比例方式(0不抽取，1抽取订单总金额部分，2抽取配送费部分，3抽取支付金额部分)
        if (null == SYS_SETTINGS.PLAT_SHARE_CITY_ADMIN_MONEY_TYPE) {
            settingUserVO.setPlatShareCityAdminMoneyType(0);
        } else {
            settingUserVO.setPlatShareCityAdminMoneyType(SYS_SETTINGS.PLAT_SHARE_CITY_ADMIN_MONEY_TYPE);
        }
        //区域主管是否参与分成（0不参与，1参与）
        if (null == SYS_SETTINGS.AGENT_MANAGER_IS_SHARE_MONEY) {
            settingUserVO.setAgentManagerIsShareMoney(0);
        } else {
            settingUserVO.setAgentManagerIsShareMoney(SYS_SETTINGS.AGENT_MANAGER_IS_SHARE_MONEY);
        }
        //获取不到店铺时，显示默认店铺 1显示 0不显示
        if (null == SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
            settingUserVO.setNoShopShowDefault(0);
        } else {
            settingUserVO.setNoShopShowDefault(SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT);
        }

        //配送员管理方式 是按城市还是按代理  1按城市 2按代理
        if (null == SYS_SETTINGS.POSTMAN_IN_CITY_OR_AGENT) {
            settingUserVO.setPostmanInCityOrAgent(0);
        } else {
            settingUserVO.setPostmanInCityOrAgent(SYS_SETTINGS.POSTMAN_IN_CITY_OR_AGENT);
        }
        //系统类型 1标准版、2专业版、3企业版
        if (null == SYS_SETTINGS.SYS_TYPE) {
            settingUserVO.setSysType(0);
        } else {
            settingUserVO.setSysType(SYS_SETTINGS.SYS_TYPE);
        }

        //配送员是否参与分成（0不参与，1总金额，2参与配送费部分,3按商圈设置的配送员
        if (null == SYS_SETTINGS.POSTMAN_SHARE_MONEY) {
            settingUserVO.setPostmanShareMoney(0);
        } else {
            settingUserVO.setPostmanShareMoney(SYS_SETTINGS.POSTMAN_SHARE_MONEY);
        }

        // 是否按照实际骑行距离进行计算配送费
        if (null == SYS_SETTINGS.IS_RIDING_DISTANCE) {
            settingUserVO.setIsRidingDistance(0);
        } else {
            settingUserVO.setIsRidingDistance(SYS_SETTINGS.IS_RIDING_DISTANCE);
        }

        // 是否有最小限购数量
        if (null == SYS_SETTINGS.HAS_MIN_BUY_COUNT) {
            settingUserVO.setHasMinBuyCount(0);
        } else {
            settingUserVO.setHasMinBuyCount(SYS_SETTINGS.HAS_MIN_BUY_COUNT);
        }
        // 店铺-支付完成红包
        if (null == SYS_SETTINGS.SHOP_HAS_PAY_FINISH_PACKET) {
            settingUserVO.setShopHasPayFinishPacket(0);
        } else {
            settingUserVO.setShopHasPayFinishPacket(SYS_SETTINGS.SHOP_HAS_PAY_FINISH_PACKET);
        }
        // 分销模式
        if (null == SYS_SETTINGS.DISTRIBUTION_MODEL) {
            settingUserVO.setDistributionModel(0);
        } else {
            settingUserVO.setDistributionModel(SYS_SETTINGS.DISTRIBUTION_MODEL);
        }
        // 是否有分销提到到余额 1 有 0 没有
        if (null == SYS_SETTINGS.HAS_DISTRIBUTE_POP_TO_WALLET) {
            settingUserVO.setHasDistributePopToWallet(0);
        } else {
            settingUserVO.setHasDistributePopToWallet(SYS_SETTINGS.HAS_DISTRIBUTE_POP_TO_WALLET);
        }
        // 是否有店铺自取单分成设置
        if (null == SYS_SETTINGS.HAS_SHOP_ZIQU_SHARE) {
            settingUserVO.setHasShopZiQuShare(0);
        } else {
            settingUserVO.setHasShopZiQuShare(SYS_SETTINGS.HAS_SHOP_ZIQU_SHARE);
        }

        // 商家税率
        if (null == SYS_SETTINGS.TAX_CALCULATION_TYPE) {
            settingUserVO.setTaxCalculationType(0);
        } else {
            settingUserVO.setTaxCalculationType(SYS_SETTINGS.TAX_CALCULATION_TYPE);
        }
        // 店铺优惠比例
        if (null == SYS_SETTINGS.HAS_ZIQU_AWARD) {
            settingUserVO.setHasZiQuAward(0);
        } else {
            settingUserVO.setHasZiQuAward(SYS_SETTINGS.HAS_ZIQU_AWARD);
        }
        // 店铺优惠比例
        settingUserVO.setHasGoodsDistribute(SYS_SETTINGS.HAS_GOODS_DISTRIBUTE); // 团购分销模式
        settingUserVO.setOrderCommentNeedVerify(SYS_SETTINGS.ORDER_COMMENT_NEED_VERIFY); // 评论是否需要审核
        settingUserVO.setHasReduceDeliveryPriceGame(SYS_SETTINGS.HAS_REDUCE_DELIVERY_PRICE_GAME); // 是否有配送费满减活动
        settingUserVO.setHasLastOnlineTime(SYS_SETTINGS.HAS_LAST_ONLINE_TIME); // 是否有最后在线时间
        settingUserVO.setAwardCanExceedPrice(SYS_SETTINGS.AWARD_CAN_EXCEED_PRICE); // 满减金额可以超过订单总价格 0 不可以  1 可以
        settingUserVO.setHasMemberRecharge(SYS_SETTINGS.HAS_MEMBER_RECHARGE); // 是否有会员充值红包
        settingUserVO.setDistinguishShopRecommend(SYS_SETTINGS.DISTINGUISH_SHOP_RECOMMEND); // 是否区分店铺推荐 1 区分 0 不区分
        settingUserVO.setIsPostmanServiceShop(SYS_SETTINGS.POSTMAN_SERVICE_SHOP); // 骑手服务店铺模式
        settingUserVO.setHasBaoXian(SYS_SETTINGS.HAS_BAO_XIAN); // 是否有保险
        settingUserVO.setCustomSystemType(SYS_SETTINGS.CUSTOM_SYSTEM_TYPE); // 制系统类型 0 外卖系统 1 配送系统类型（如一乙）
        settingUserVO.setDeliveryTimeByDistance(SYS_SETTINGS.DELIVERY_TIME_BY_DISTANCE); // 配送时长按照距离计算
        settingUserVO.setHasDeliveryWorkDays(SYS_SETTINGS.HAS_DELIVERY_WORK_DAYS); // 是否有配送日设置
        settingUserVO.setHasBrowseHistory(SYS_SETTINGS.HAS_BROWSE_HISTORY); // 是否有浏览记录
        settingUserVO.setCityLineFeeUseDistance(SYS_SETTINGS.CITY_LINE_FEE_USE_DISTANCE); // 线路费用是否使用距离进行计算
        settingUserVO.setCityLineFeeCalculateType(SYS_SETTINGS.CITY_LINE_FEE_CALCULATE_TYPE); // 线路费用计算方式 0 默认计算方式 1 线路基础费用*人数 + 增值费用 2 (基础费用+线路费用) * 人数
        settingUserVO.setOrderAddressShowCity(SYS_SETTINGS.ORDER_ADDRESS_SHOW_CITY); // 线路费用是否使用距离进行计算
        settingUserVO.setAgentManagerDaiGou(SYS_SETTINGS.AGENT_MANAGER_DAI_GOU); // 线路费用是否使用距离进行计算
        settingUserVO.setCityAdminManagerBianMin(SYS_SETTINGS.CITY_ADMIN_MANAGER_BIANMIN); // 城市代理管理便民信息
        settingUserVO.setHasMinShopMoney(SYS_SETTINGS.HAS_MIN_SHOP_MONEY); // 是否有最小抽成金额

        settingUserVO.setHasRequiredGoodsCategory(SYS_SETTINGS.HAS_REQUIRED_GOODS_CATEGORY); //  是否有必选商品分类
        settingUserVO.setNotPayAutoCancelOrderTime(SYS_SETTINGS.NOT_PAY_AUTO_CANCEL_ORDER_TIME); //  未支付自动取消订单时间

        settingUserVO.setCityAdminCanManagePacket(SYS_SETTINGS.CITY_ADMIN_CAN_MANAGE_PACKET); //  城代是否可以管理红包
        settingUserVO.setHasShopJoinVipGameManager(SYS_SETTINGS.HAS_SHOP_JOIN_VIP_GAME_MANAGER); //  管理店铺参与vip会员活动 0 全都可以 1 根据商家独立设置
        settingUserVO.setShopChouYongModel(SYS_SETTINGS.SHOP_CHOU_YONG_MODEL); //   店铺抽佣方式 0 默认 1 按照阶梯固定抽成
        settingUserVO.setIsOtherPost(SYS_SETTINGS.IS_OTHER_POST);      // 是不是第三方配送  2 第三方配送  1 本系统配送
        settingUserVO.setIsOpenShopSettlement(SYS_SETTINGS.IS_OPEN_SHOP_SETTLEMENT);      // 是否开启账单结算 0 不开启  直接到账 1 开启账单结算
        settingUserVO.setHasMuchShopOrderSet(SYS_SETTINGS.HAS_MUCH_SHOP_ORDER_SET);      // 是否有多店铺订单设置 0 全部 1 自己设置店铺 2 全部支持
        settingUserVO.setNewUserOrderDiscountRate(SYS_SETTINGS.NEW_USER_ORDER_DISCOUNT_RATE);      // 新用户折扣百分比 0 免单   50 则打五折 -1 不打折

        settingUserVO.setIsOpenDiscountExchangeCode(SYS_SETTINGS.IS_OPEN_DISCOUNT_EXCHANGE_CODE);      // 是否开启折扣兑换码 0 不启用 1 启用

        // 平台抢单模式
//        if (null == SYS_SETTINGS.GRAB_ORDER_MODE) {
//            settingUserVO.setGrabOrderMode(0);
//        } else {
//            settingUserVO.setGrabOrderMode(SYS_SETTINGS.GRAB_ORDER_MODE);
//        }
        // 平台抢单模式
//        if (SYS_SETTINGS.ADMIN_MANAGER_GRAB_ORDER_MODE == 1 // 代理管理自己的商圈模式
//                && (user != null && user.getUserType() != UserType.SUPER_COMPANY && user.getUserType() != UserType.SUPER_ADMIN) // 代理
//                && SysCityAdminMan.isUpperLowerSysAdmin()) { // 并且是上下级代理模式  如果不是 代理的上级模式的话 则会平台的
//            String username = SysCityCompanyMan.getSysCompanyOwnUsername(user.getUsername());
//            List<SysCityAdmin> cityAdmins = SysCityAdminMemory.getInstance().listOfUsername(username);
//            if (!ValidateUtil.isAbsList(cityAdmins)) {
//                settingUserVO.setGrabOrderMode(0);
//            } else {
//                settingUserVO.setGrabOrderMode(cityAdmins.get(0).getGrabOrderMode());
//            }
//        } else {
//            if (null == SYS_SETTINGS.GRAB_ORDER_MODE) {
//                settingUserVO.setGrabOrderMode(0);
//            } else {
//                settingUserVO.setGrabOrderMode(SYS_SETTINGS.GRAB_ORDER_MODE);
//            }
//        }
        settingUserVO.setGrabOrderMode(GrabOrderModeMan.getGrabOrderModeByAdmin(user == null ? "" : user.getUsername()));
        settingUserVO.setAdminManagerGrabOrderMode(SYS_SETTINGS.ADMIN_MANAGER_GRAB_ORDER_MODE);

        settingUserVO.setAdminManagerDispatchOrderMode(SYS_SETTINGS.ADMIN_MANAGER_DISPATCH_ORDER_MODE); // 管理员是够可以管理自动派单模式
        // 到店验证码长度 (0 标识，默认12位)
        if (null == SYS_SETTINGS.DAO_DIAN_VERIFY_LENGTH) {
            settingUserVO.setDaoDianVerifyLength(0);
        } else {
            settingUserVO.setDaoDianVerifyLength(SYS_SETTINGS.DAO_DIAN_VERIFY_LENGTH);
        }
        // 是不是 展示修改后的销量
        if (null == SYS_SETTINGS.HAS_SHOW_SELL_COUNT) {
            settingUserVO.setHasShowSellCount(0);
        } else {
            settingUserVO.setHasShowSellCount(SYS_SETTINGS.HAS_SHOW_SELL_COUNT);
        }

        // 是否显示特殊店铺 0不显示 1显示
        if (null == SYS_SETTINGS.SHOW_SPECIAL_SHOP) {
            settingUserVO.setShowSpecialShop(0);
        } else {
            settingUserVO.setShowSpecialShop(SYS_SETTINGS.SHOW_SPECIAL_SHOP);
        }
        // 是不是上下级代理模式
        if (null == SYS_SETTINGS.IS_UPPER_LOWER_SYSADMIN) {
            settingUserVO.setIsUpperLowerSysAdmin(0);
        } else {
            settingUserVO.setIsUpperLowerSysAdmin(SYS_SETTINGS.IS_UPPER_LOWER_SYSADMIN);
        }
        // 为代理创建默认的公司
        if (null == SYS_SETTINGS.IS_SYSADMIN_CREATE_COMPANY) {
            settingUserVO.setIsSysadminCreateCompany(0);
        } else {
            settingUserVO.setIsSysadminCreateCompany(SYS_SETTINGS.IS_SYSADMIN_CREATE_COMPANY);
        }
        // 打印小票是否打印二维码
        if (null == SYS_SETTINGS.IS_PRINT_QR_CODE) {
            settingUserVO.setIsPrintQRCode(0);
        } else {
            settingUserVO.setIsPrintQRCode(SYS_SETTINGS.IS_PRINT_QR_CODE);
        }
        // 店铺类别开关
        if (null == SYS_SETTINGS.HAS_SHOP_TYPE_OPEN) {
            settingUserVO.setHasShopTypeOpen(0);
        } else {
            settingUserVO.setHasShopTypeOpen(SYS_SETTINGS.HAS_SHOP_TYPE_OPEN);
        }
        // 商圈是否启用电子围栏模式
        if (null == SYS_SETTINGS.IS_ELECTRONICFENCE) {
            settingUserVO.setIsElectronicFence(0);
        } else {
            settingUserVO.setIsElectronicFence(SYS_SETTINGS.IS_ELECTRONICFENCE);
        }

        // 是否开启商家银行卡绑定校验 1开启,0不开启
        if (null == SYS_SETTINGS.SHOP_BIND_WALLET_CARD_NEED_CHECK) {
            settingUserVO.setShopBindWalletCardNeedCheck(0);
        } else {
            settingUserVO.setShopBindWalletCardNeedCheck(SYS_SETTINGS.SHOP_BIND_WALLET_CARD_NEED_CHECK);
        }

        // 开启店铺在线统计
        if (null == SYS_SETTINGS.SHOP_ONLINE) {
            settingUserVO.setShopOnline(0);
        } else {
            settingUserVO.setShopOnline(SYS_SETTINGS.SHOP_ONLINE);
        }

        // 骑手新订单排序 0默认排序最新订单在最上面   1最新订单在最下面
        if (null == SYS_SETTINGS.POSTMAN_NEW_ORDER_SORT) {
            settingUserVO.setPostmanNewOrderSort(0);
        } else {
            settingUserVO.setPostmanNewOrderSort(SYS_SETTINGS.POSTMAN_NEW_ORDER_SORT);
        }

        // 跑腿距离比例单位(%) 0 默认未设置比例 120 则 距离是原来的1.2倍
        settingUserVO.setRunningDistanceRate(SYS_SETTINGS.RUNNING_DISTANCE_RATE);
        //店铺首页商品排序  降序还是升序 1 降序 0 升序
        settingUserVO.setGoodsSortOrderNoMaxTop(SYS_SETTINGS.GOODS_SORT_ORDER_NO_MAX_TOP);
        // 是不是有微信转账的功能
        settingUserVO.setHasTransferWxAli(SYS_SETTINGS.HAS_TRANSFER_WX_ALI);

        // 是否开启自动派单功能 1开启,0不开启
        if (null == SYS_SETTINGS.IS_OPEN_AUTO_DISPATCH_ORDER) {
            settingUserVO.setIsOpenAutoDispatchOrder(0);
        } else {
            settingUserVO.setIsOpenAutoDispatchOrder(SYS_SETTINGS.IS_OPEN_AUTO_DISPATCH_ORDER);
        }

        // 店铺自动上下班模式  1 原来的默认 2 商家上班会自动开启自动上下班功能，停止营业会关闭自动自动上下班
        if (null == SYS_SETTINGS.SHOP_AUTO_CLOSE_MODE) {
            settingUserVO.setShopAutoCloseMode(0);
        } else {
            settingUserVO.setShopAutoCloseMode(SYS_SETTINGS.SHOP_AUTO_CLOSE_MODE);
        }
        // 首页提示信息
        if (ValidateUtil.isNull(SYS_SETTINGS.HOME_PAGE_TIP)) {
            settingUserVO.setHomePageTip("");
        } else {
            settingUserVO.setHomePageTip(SYS_SETTINGS.HOME_PAGE_TIP);
        }
        // 登录方式 0 username 登录 phone 手机号登录
        if (null == SYS_SETTINGS.LOGIN_TYPE_BY) {
            settingUserVO.setLoginTypeBy(0);
        } else {
            settingUserVO.setLoginTypeBy(SYS_SETTINGS.LOGIN_TYPE_BY);
        }
//         默认下单多久以后的订单  单位分钟
        if (null == SYS_SETTINGS.DEFAULT_MINUTE_LATER) {
            settingUserVO.setDefaultMinuteLater(0); // 默认不处理
        } else {
            settingUserVO.setDefaultMinuteLater(SYS_SETTINGS.DEFAULT_MINUTE_LATER);
        }
        //   提现整数
        if (null == SYS_SETTINGS.USER_MULTIPLE_OF_HUNDRED) {
            settingUserVO.setUserMultipleOfHundred(0); // 默认不处理
        } else {
            settingUserVO.setUserMultipleOfHundred(SYS_SETTINGS.USER_MULTIPLE_OF_HUNDRED);
        }

        //平台为店铺自动接单  0不自动接  1自动接
        if (null == SYS_SETTINGS.SHOP_AUTO_APPLY_BY_PLATFORM) {
            settingUserVO.setShopAutoApplyByPlatform(0); // 默认不处理
        } else {
            settingUserVO.setShopAutoApplyByPlatform(SYS_SETTINGS.SHOP_AUTO_APPLY_BY_PLATFORM);
        }

        // 微信支付宝使用中间第三方 0系统内部
        if (null == SYS_SETTINGS.WX_ALI_USE_TRI) {
            settingUserVO.setWxAliUseTri(0); // 默认不处理
        } else {
            settingUserVO.setWxAliUseTri(SYS_SETTINGS.WX_ALI_USE_TRI);
        }


        //  服务通知模板ID
        if (null == SYS_SETTINGS.IS_PUSH_WITH_GZH || 0 == 1 - SYS_SETTINGS.IS_PUSH_WITH_GZH) {
            settingUserVO.setTemplateId("");
        } else {
            SysSetting sysSetting = SysSettingMemory.getInstance().getByCode("isPushWithGzh");
            settingUserVO.setTemplateId(sysSetting.getNote()); // 返回模板Id
        }
        //验证用户有效性
        if (user != null) {
//                //当前账号是否有
//                if (OrderInfoMemory.getInstance().hasOrder(user.getUsername())) {
//                    settingUserVO.setHasOrder(1);
//                }
            // 当前账号是否有订单
            if (UserOrderMan.userHasOrder(user.getUsername())) {
                settingUserVO.setHasOrder(1);
            }
            // 当前用户是否有折扣订单
            if (UserOrderMan.userHasDiscountOrder(user.getUsername())) {
                settingUserVO.setHasDiscountOrder(1);
            }
        }
        return AjaxResult.successResult(settingUserVO);
    }


    // 获取系统里的接口地址
    @RequestMapping(method = RequestMethod.POST, value = "/user/sys/url/path")
    @ResponseBody
    public String sys_user_path_list(String token) {
        SysConfigPathUserVO pathUserVO = new SysConfigPathUserVO();
        pathUserVO.setFenXiaoUrl(SYS_CONFIG_PATH.FEN_XIAO_SERVICE_URL);
        pathUserVO.setFenXiaoKey(SYS_CONFIG_PATH.FEN_XIAO_SERVICE_KEY);

        pathUserVO.setJifenUrl(SYS_CONFIG_PATH.INTEGRAL_SERVICE_URL);

        pathUserVO.setBaoxianUrl(SYS_CONFIG_PATH.BAO_XIAN_SERVICE_URL);

        return AjaxResult.successResult(pathUserVO);
    }


}
